package miiteen.customsportal.basic.service;

import miiteen.hr.pubconfig.CurrentHrInfo;
import miiteen.hr.user.beans.UserUserInfo;
import miiteen.sys.login.bean.UserShiro;
import miiteen.sys.login.utils.LoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import miiteen.data.dao.BaseDao;
import miiteen.data.service.impl.BaseServiceImpl;

import miiteen.customsportal.basic.beans.BasicBillboards;
import miiteen.customsportal.basic.dao.BasicBillboardsDao;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Name: CustomsPortal_Basic_Billboards
 * Des: -Service
 * Author: yulp
 * Date: 2020-07-03
 */
@Service("basicBillboardsService")
public class BasicBillboardsService extends BaseServiceImpl<BasicBillboards> {

    @Autowired
    private BasicBillboardsDao basicBillboardsDao;

    @Override
    protected BaseDao<BasicBillboards> getDao() {
        return basicBillboardsDao;
    }


    public long save(BasicBillboards basicBillboards){
        UserShiro.ShiroUser shiroUser= LoginUtil.getCurUser();
        UserUserInfo user= CurrentHrInfo.getUserInfo(shiroUser);
        Map<String,Object> map=new HashMap<>();
        boolean overOne=false;

        map.put("editId",basicBillboards.getId());
      
        overOne= basicBillboardsDao.findListByMap(map).size()>0;
        if(basicBillboards.getId()>0){
            //修改
            basicBillboards.setUpdateId(user.getId());//修改人id
            basicBillboards.setUpdateTime(new Date());//修改时间
            basicBillboards.setUpdator(user.getTrueName());//修改人名
        }else{
            //保存
            if(overOne) return -100L;
            basicBillboards.setOrganizeId(2001);//组织id
            basicBillboards.setCreateId(user.getId());//创建人id
            basicBillboards.setCreateTime(new Date());//创建时间
            basicBillboards.setCreator(user.getTrueName());//创建人名
        }

        return basicBillboardsDao.save(basicBillboards);
    }

}
